import * as cc from 'cc';
import {
    AutoBindKeys,
    KeyBinding,
} from 'db://assets/component/input/InputUtil';
import { FollowNode } from 'db://assets/component/node/FollowNode';

const { ccclass, property } = cc._decorator;

@ccclass('BorrowTest')
@AutoBindKeys
export class BorrowTest extends cc.Component {
    @property(cc.Node)
    node1: cc.Node = null!;

    @property(cc.Node)
    node2: cc.Node = null!;

    @property(FollowNode)
    borrow: FollowNode = null!;

    @KeyBinding(cc.KeyCode.KEY_A)
    change1() {
        console.log('change-1');
        this.borrow.attachTo(
            this.borrow.node,
            this.node1,
            this.borrow.node.children[0],
        );
    }

    @KeyBinding(cc.KeyCode.KEY_S)
    change2() {
        console.log('change-2');
        this.borrow.attachTo(
            this.borrow.node,
            this.node2,
            this.borrow.node.children[0],
        );
    }

    @KeyBinding(cc.KeyCode.KEY_D)
    detach() {
        console.log('change-2');
        this.borrow.detach(this.borrow.node);
    }
}
